import Vue from 'vue'
import Vuex from 'vuex'
import { marketSaleParam } from './marketSaleParam'
Vue.use(Vuex)

let originSignFormData = ({
  phone: '',
  uuid: '',
  imgCode: '',
  imgStr: '',
  randomCode: '',
  // industryCategory: '',
  // industryName: '',
  brandName:'',
  companyName:'',
  staffSize: '',
  userName: '',
  email: '',
  // province: '',
  // city: '',
  // area: '',
  password: '',
  companySizeList: [],
  industryList: [],
  industryIds: [],
  regionIds: [],
  regionData: [],
  inviteUserList: [],
  permList: [],
  step: 1,
})

const signModule = {
  state: ({
    ...originSignFormData
  }),
  mutations: {
    updateSignForm(state, data) {
      _.map(data, (value, key) => {
        state[key] = value
      })
    },
    resetSignForm(state) {
      _.map(originSignFormData, (value, key) => {
        console.log(value, key)
        state[key] = value
      })
    }
  },
}

const productionModule = {
  state: {
    categoryTree: [],
  },
  mutations: {
    updateProductionData(state, data) {
      _.map(data, (value, key) => {
        state[key] = value
      })
    }
  },
}

const userModule = {
  state: !!sessionStorage.getItem("tokenName") ? JSON.parse(sessionStorage.getItem("userData")) : {
    phone: '',
    userName: '',
  },
  mutations: {
    updateUserData(state, data) {
      _.map(data, (value, key) => {
        state[key] = value
      })
    },
    clearUserData(state) {
      _.map(state, (value, key) => {
        state[key] = ''
      })
    }
  },
}
export default new Vuex.Store({
    state: {
      id: sessionStorage.getItem('ID') || '',//市场id
      itemData: JSON.parse(sessionStorage.getItem('itemData')) || [],
      brand: JSON.parse(sessionStorage.getItem('brand')) || [],
      brandArr: JSON.parse(sessionStorage.getItem('brandArr')) || [],
      isMarket: JSON.parse(sessionStorage.getItem('isMarket')) || false,
      marketName: (sessionStorage.getItem('marketName')) || '',
      marketData: JSON.parse(sessionStorage.getItem('marketData')) || [],
      // categoryId:sessionStorage.getItem('categoryID') || '',//品类id
    },
    mutations: {
      //市场id
      setId(state, id) {
        sessionStorage.setItem('ID', id)
        state.id = id
        console.log(4567890)

      },
      //单个市场的数组值
      setMarket(state, itemData) {
        sessionStorage.setItem('itemData', JSON.stringify(itemData))
        state.itemData = itemData

        console.log(state.itemData)
      },

      //品牌数组
      //  setBrand(state,brand){
      //    console.log(brand)
      //   sessionStorage.setItem('brand',JSON.stringify(brand))
      //   state.brand=brand
      //  },
      //品牌型号数组
      setBrandArr(state, brandArr) {
        console.log(brandArr)
        sessionStorage.setItem('brandArr', JSON.stringify(brandArr))
        state.brandArr = brandArr
      },
      //  setMarketName(state,marketName){
      //   sessionStorage.setItem('itemData',JSON.stringify(itemData))
      //   state.itemData=itemData
      //  }
      isMarket(state, bl) {
        sessionStorage.setItem('isMarket', (bl))
        state.isMarket = bl
      },
      setMarketName(state, name) {
        sessionStorage.setItem('marketName', (name))
        state.marketName = name
      },
      setMarketData(state, marketData) {
        sessionStorage.setItem('marketData', JSON.stringify(marketData))
        state.marketData = marketData
      },
      // setCategoryId(state,categoryId){
      //   sessionStorage.setItem('categoryID',categoryId)
      //   state.categoryId=categoryId
      // }
    },


    modules: {
      signForm: signModule,
      user: userModule,
      productionData: productionModule,
      marketSaleParam: marketSaleParam
    }
  })
